#ifndef FILETHREAD_H
#define FILETHREAD_H

#include <QThread>
#include <QWidget>
#include <QTcpSocket>
#include <QListWidgetItem>
#include <QFileDialog>
#include <QDesktopServices>
#include <queue>
#include "constant.h"
#include "Headers/algorithm.h"

class FileThread : public QThread
{
    Q_OBJECT
public:
    FileThread(QString ServerIp,QString UserName,QString ToUserName);
protected:
    void ToServerFileInfo(QTcpSocket *socket);
    void ToServerFileData(QTcpSocket *socket);
    QPair<QString,qint64> getFileContent(QString filePath);
    void fileInfoRead(QTcpSocket *socket,QMap<QString, QVariant> map);
    void fileDataRead(QTcpSocket *socket);
    void run() override;
private:
    QString m_downloadPath;
    QString ServerIp;
    QString UserName;
    QString ToUserName;
    qint64 FileTcpPort;
    QTcpSocket* FileTcpSocket;
    void FileSocketInit();
    /*File*/
    QString ServerFilePath;
    bool is_images;
    QString toServerFileSize;
    qint64 m_fileInfoWriteBytes;
    qint64 typeMsgSize;
    qint64 m_sendFileSize;
    QFile m_localFile;
    QString m_sendFilePath;
    MyFileInfo*serverFile;
    QString getServerFileSize;
    QString filePath;
    bool is_dow;
    QString User;
    queue<QString>file;//文件上传队列
signals:
    void FilePath(QString,QString);
    void sendData(QByteArray);
    void receive();
public slots:
    void getPath(QString);
};

#endif // FILETHREAD_H
